package com.Isb.Golf.inputgolfscore;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.text.format.Time;

import com.Isb.Golf.inputgolfscore.connectivity.InputGolfScoreConnectivityManager;
import com.Isb.Golf.inputgolfscore.data.DataManager;

public class InputGolfScoreModel {

	private static final InputGolfScoreModel instance = new InputGolfScoreModel();

	private DataManager dataMng = null;
	private Context appContext;
	private InputGolfScoreConnectivityManager connectManager = null;

	public static InputGolfScoreModel getInstance() {
		return instance;
	}

	private InputGolfScoreModel() {
		dataMng = new DataManager();
	}

	public void init(Context context){
		connectManager = new InputGolfScoreConnectivityManager(context);
	}

	public void setContext(Context context){
		appContext = context;
	}

	public void PlayDayInfo(Time time){
		dataMng.setDate(time);
	}

	public void courseNameInfo(String name){
		dataMng.setCourseName(name);
	}

	public void setcourseData(int holeNo, String holePar, String holeHDC){
		int intPar = 0;
		int intHDC = 0;

		if(!holePar.isEmpty()){
			intPar = Integer.parseInt(holePar);
		}

		if(!holeHDC.isEmpty()){
			intHDC = Integer.parseInt(holeHDC);
		}

		dataMng.setCourseDataInfomation(holeNo, intPar, intHDC);
	}

	public String LoadPlayerName(){
		SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(appContext);
		String playerName = pref.getString(appContext.getResources().getString(R.string.pref_input_name), "" );

		dataMng.setPlayerInfomation(playerName);
		return  playerName;
	}

	public void SavePlayerName(String playerName){
		dataMng.setPlayerInfomation(playerName);

		SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(appContext);
		Editor editor = pref.edit();
		editor.putString(appContext.getResources().getString(R.string.pref_input_name), playerName);
		editor.commit();

	}
}
